package com.sinopec.yelofixedreader.uhf.dialog

import android.content.DialogInterface
import android.graphics.Point
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.TextView
import com.sinopec.basemodule.dialog.DFBase
import com.sinopec.yelofixedreader.uhf.R

/**
 * lwj at 2023/6/1
 * 数量错误弹窗
 */
class AmountErrorDialogBak(
    private val shouldScan: String,
    private val alreadyScan: String,
    private val onDismissCall:()->Unit
) : DFBase() {

    init {
        isCancelable = false
    }

    override fun createView(): Int {
        return R.layout.dialog_amount_error_bak
    }

    override fun initView(view: View?) {
        //应扫
        view?.findViewById<TextView>(R.id.tvShouldScan)?.text = shouldScan
        //已经扫
        view?.findViewById<TextView>(R.id.tvAlreadyScan)?.text = alreadyScan

        //确认按钮关闭
        view?.findViewById<View>(R.id.cvOk)?.setOnClickListener {
            dismiss()
        }
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        this.onDismissCall()
    }

    override fun setDialogParams(window: Window) {
        val point = Point()
        window.windowManager.defaultDisplay.getSize(point)

        //设置宽度百分比
        //#第一种
        window.setLayout(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        );

        val layoutParams = window.attributes
        //#第二种
//        layoutParams.width = point.x
//        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT

        //设置dialog位置
        layoutParams.gravity = Gravity.CENTER
        //设置dialog动画
        //layoutParams.windowAnimations = R.style.xxxx
        window.attributes = layoutParams

    }
}